package com.eshop.we.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.eshop.we.business.ExchangeBusiness;
import com.eshop.we.business.ExchangeDetailBusiness;
import com.eshop.we.business.ExchangeOrderBusiness;
import com.eshop.we.business.ExchangeOrderDetailBusiness;
import com.eshop.we.exchange.form.ExchangeForm;
import com.eshop.we.exchangedetail.entity.ExchangeDetail;
import com.eshop.we.result.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Api(value = "换书管理接口", description = "换书管理接口")
@RestController
@RequestMapping("/exchange")
public class ExchangeController extends BaseController{

    @Autowired
    ExchangeBusiness exchangeBusiness;

    @Autowired
    ExchangeOrderBusiness exchangeOrderBusiness;

    @Autowired
    ExchangeDetailBusiness exchangeDetailBusiness;

    @Autowired
    ExchangeOrderDetailBusiness exchangeOrderDetailBusiness;

    @ApiOperation(value = "查询发布中的换书信息",notes = "查询发布中的换书信息")
    @GetMapping("/getexchange")
    public Result  getExchange( @ApiIgnore Integer userId){
       return Result.success(exchangeBusiness.selectExchangeList(userId));
    }

    @ApiOperation(value = "匹配发布中的换书信息",notes = "匹配发布中的换书信息")
    @GetMapping("/mathexchange")
    public  Result getMathExchange(@ApiParam(value = "信息id", required = true) Integer exchangeId, @ApiIgnore Integer schoolId,@ApiIgnore Integer userId){
      return Result.success(exchangeBusiness.selectMathExchange(exchangeId,schoolId,userId));
    }

    @ApiOperation(value = "查看发布中的换书信息详情",notes = "查看发布中的换书信息详情")
    @GetMapping("/getexchangedetail")
    public Result getExchangeDetail (@ApiParam(value = "信息id", required = true) Integer exchangeId){
        return Result.success(exchangeDetailBusiness.selectList(new EntityWrapper<ExchangeDetail>().eq("exchange_id",exchangeId)));
    }


    @ApiOperation(value = "删除换书订单信息",notes = "删除换书订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", required = true, dataType = "Integer", paramType = "query", value = "换书信息id"),
    })
    @DeleteMapping("/delexchange")
   public Result delectExchange(@RequestParam(required = true) Integer id){
       return Result.success(exchangeBusiness.updateExchangeDel(id));
   }

    @ApiOperation(value = "查询换书订单记录",notes = "查询换书订单记录")
    @GetMapping("/getexchangeorder")
   public Result getExchangeOrder( @ApiIgnore Integer userId){
        return   Result.success(exchangeOrderDetailBusiness.selectExchangeRecord(userId));
   }

    @ApiOperation(value = "查询换书订单记录详情",notes = "查询换书订单记录详情")
    @GetMapping("/getexchangeorderdetail")
    public Result getExchangeOrderDetail(@RequestParam(required = true) Integer orderId,@ApiIgnore Integer userId){
        return   Result.success(exchangeOrderDetailBusiness.selectOrderDetail(orderId,userId));
    }

    /**
     * 添加换书信息
     * @return
     */
    @RequestMapping("/add")
    public Result add(ExchangeForm exchange){
        exchangeBusiness.add(exchange);
        return Result.success();
    }

}
